package com.jasperframework.boot.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesLoader {

	private static final Logger logger = LoggerFactory
			.getLogger(PropertiesLoader.class);
	private static final Properties properties = new Properties();


	static {
		String[] arrStrings = new String[]{"/application.properties"};

		for(String s : arrStrings){
			InputStream in = PropertiesLoader.class
					.getResourceAsStream(s);

			if (in == null) {
				logger.info("image.properties not found");
			} else {
				if (!(in instanceof BufferedInputStream))
					in = new BufferedInputStream(in);
				try {
					properties.load(in);
					in.close();
					logger.debug("system.properties loaded");
				} catch (Exception e) {
					logger.error("Error while processing system.properties");
					throw new RuntimeException(
							"Error while processing system.properties", e);
				}
			}
		}
	}


	public static String getProperty(String key) {
		return properties.getProperty(key);
	}

	public static void setProperty(String key, String value) {
		properties.setProperty(key, value);
	}

}
